package io.dy.listener;

import cn.hutool.json.JSONUtil;
import io.dy.model.OrderlyModel;
import org.apache.rocketmq.common.message.MessageExt;
import org.apache.rocketmq.spring.annotation.ConsumeMode;
import org.apache.rocketmq.spring.annotation.RocketMQMessageListener;
import org.apache.rocketmq.spring.core.RocketMQListener;
import org.springframework.stereotype.Component;

/**
 * @author : dmj
 * @date: 2024/8/27 4:28 下午
 * @description: 顺序消息监听器
 */
@Component
@RocketMQMessageListener(topic = "bootOrderlyTopic",
        consumerGroup = "delayed-consumer-group",
        consumeMode = ConsumeMode.ORDERLY
)
public class OrderlyListener implements RocketMQListener<MessageExt> {

    @Override
    public void onMessage(MessageExt messageExt) {
        OrderlyModel orderlyModel = JSONUtil.toBean(new String(messageExt.getBody()), OrderlyModel.class);
        System.out.println("OrderlyListener 接收到消息为: " + orderlyModel);
    }
}
